
import { director, instantiate, Prefab, resources,Node } from "cc";
import { SceneManager } from "../Framework/Manager/SceneManager";
import Util from "../Framework/Util/Util";
import { BindNode } from "./BindNode";

export class EngineCommon
{
    static SetSceneCall(sceneManager:SceneManager,OnSceneLoaded: (_scene: any, _mode: any) => void)
    {
        // UnityEngine.SceneManagement.SceneManager.add_sceneLoaded((scene:UnityEngine.SceneManagement.Scene,mode:UnityEngine.SceneManagement.LoadSceneMode)=>{
           
        // OnSceneLoaded.apply(sceneManager,[scene,mode]);
        // })
    }

    static LoadScene(sname:string,sceneManager:SceneManager,callback:any)
    {
        // UnityEngine.SceneManagement.SceneManager.LoadScene(sname,UnityEngine.SceneManagement.LoadSceneMode.Single);
        director.loadScene(sname,(error: null | Error, scene)=>{
            callback.apply(sceneManager);
        })
    }

    static ResLoad(path:string,loadCall: (go:BindNode) => void)
    {
        resources.load<Prefab>(path,(error,aseet)=>
        {
            Util.Log("res load :",path);
            
            if (error && error.message)
            {
                console.error("loadPrefab",error.message)   
                return;
            }
            var prefab = aseet as Prefab;
            var newNode = instantiate(prefab) as Node;
            director.getScene().addChild(newNode);

            loadCall(new BindNode(newNode ));

        })
    }
}